﻿using System;
using System.Collections.Generic;
using System.Linq;
using InvestmentIntelligence.Data.Repository.Comparers.EntityModelsComparers;
using InvestmentIntelligence.DbModel.Models;

namespace InvestmentIntelligence.Data.Repository.EFImplementation
{
    public class CountryRepository : IIPRepository<Country>, ICountryUpdatableRepository
    {
       
        public Country Get(string countryCode)
        {
            return Get(dc => dc.SingleOrDefault(x => x.CountryCode == countryCode));
        }

        public new int Add(Country country)
        {
            var item = new Country
                {
                    CountryCode = country.CountryCode.ToUpper().Trim(),
                    Region = country.Region.Trim(),
                    CountryDescription = country.CountryDescription.Trim()
                };
            base.Add(item);
            return item.Id;
        }

        public List<Country> SaveNew(IEnumerable<Country> countryList)
        {
            var countries = base.GetList();
            countryList = countryList.Except(countries, new CountryCodeComparer());
            Add(countryList);
            return base.GetList();
        }
    }
}